package com.qingmeng.applyjob.portal.controller;

import com.qingmeng.applyjob.common.api.CommonPage;
import com.qingmeng.applyjob.common.api.CommonResult;
import com.qingmeng.applyjob.portal.enums.InterpolatingResult;
import com.qingmeng.applyjob.portal.model.dto.AskInterpolatingPublishParam;
import com.qingmeng.applyjob.portal.model.dto.HelpInterParam;
import com.qingmeng.applyjob.portal.model.dto.MessageToInterParam;
import com.qingmeng.applyjob.portal.model.vo.ChoosePusherVo;
import com.qingmeng.applyjob.portal.model.vo.InterpolatingListVo;
import com.qingmeng.applyjob.portal.model.vo.InterpolatingVo;
import com.qingmeng.applyjob.portal.model.vo.MyInterpolatingListVo;
import com.qingmeng.applyjob.portal.service.InterpolatingService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModelProperty;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(tags = "interpolatingController" , description = "内推接口")
@RestController
@RequestMapping("/interpolating")
public class InterpolatingController {

    @Autowired
    private InterpolatingService interpolatingService;

    @ApiOperation("发布求内推")
    @PostMapping("/publishAskInterpolating")
    private CommonResult<Integer> publishAskInterpolating(@ApiParam("发布求内推时需要填写的信息") @RequestBody AskInterpolatingPublishParam askInterpolatingPublishParam){
        InterpolatingResult interpolatingResult = interpolatingService.publishAskInterpolating(askInterpolatingPublishParam);
        if (interpolatingResult == InterpolatingResult.SUCCESS){
            return CommonResult.success(1,interpolatingResult.getMessage());
        }
        return CommonResult.failed(interpolatingResult.getMessage());
    }

    @ApiOperation("获取求内推列表")
    @GetMapping("/interpolatingList")
    private CommonResult<CommonPage<InterpolatingListVo>> interpolatingList(@ApiParam("页码") @RequestParam(value = "pageNum",defaultValue = "1") Integer pageNum,
                                                                            @ApiParam("每页信息条数") @RequestParam(value = "pageSize" ,defaultValue = "2") Integer pageSize){
        List<InterpolatingListVo> interpolatingListVos = interpolatingService.interpolatingList(pageNum, pageSize);
        if (interpolatingListVos != null && interpolatingListVos.size() > 0){
            return CommonResult.success(CommonPage.restPage(interpolatingListVos),"获取成功");
        }
        return CommonResult.failed("未查询到相关信息");
    }

    @ApiOperation("获取求内推详情")
    @GetMapping("/getAskInterpolating")
    private CommonResult<InterpolatingVo> getAskInterpolating(@ApiParam("索要获取的求内推id") @RequestParam(value = "askInterpolatingId") Long askInterpolatingId){
        InterpolatingVo askInterpolating = interpolatingService.getAskInterpolating(askInterpolatingId);
        if (askInterpolating != null){
            return CommonResult.success(askInterpolating,"获取成功");
        }
        return CommonResult.failed("未查询到相关信息");
    }

    @ApiOperation("像求内推者留言")
    @PostMapping("/messageToInter")
    private CommonResult<Integer> messageToInter(@ApiParam("留言时需要填写的相关信息") @RequestBody MessageToInterParam messageToInterParam){
        int result = interpolatingService.messageToInter(messageToInterParam);
        if (result > 0){
            return CommonResult.success(1,"留言成功");
        }
        return CommonResult.failed("留言发布失败");
    }

    @ApiOperation("帮ta推")
    @PostMapping("/helpInter")
    private CommonResult<Integer> helpInter(@ApiParam("帮ta推需要填写的相关信息") @RequestBody HelpInterParam helpInterParam){
        int result = interpolatingService.helpInter(helpInterParam);
        if (result > 0){
            return CommonResult.success(1,"内推信息发送成功，Ta会受到您的内推信息和留言，请在【我的内推】中查看Ta的反馈");
        }
        return CommonResult.failed("操作失败");
    }

    @ApiOperation("获取我的未响应的求内推列表")
    @GetMapping("/getMyNotRespondInterList")
    private CommonResult<CommonPage<MyInterpolatingListVo>> getMyNotRespondInterList(@ApiParam("页码") @RequestParam(value = "pageNum",defaultValue = "1") Integer pageNum,
                                                                              @ApiParam("每页信息条数") @RequestParam(value = "pageSize" ,defaultValue = "2") Integer pageSize){
        List<MyInterpolatingListVo> interpolatingListVos = interpolatingService.getMyNotRespondInterList(pageNum, pageSize);
        if (interpolatingListVos != null && interpolatingListVos.size() > 0){
            return CommonResult.success(CommonPage.restPage(interpolatingListVos),"获取成功");
        }
        return CommonResult.failed("未查询到相关信息");
    }

    @ApiOperation("修改我的求内推（未响应状态下）")
    @PostMapping("/changeMyInter")
    private CommonResult<Integer> changeMyInter(@ApiParam("修改内推的相关信息") @RequestBody AskInterpolatingPublishParam askInterpolatingPublishParam,
                                                @ApiParam("所要修改的求内推id号") @RequestParam(value = "interId") Long interId){
        InterpolatingResult interpolatingResult = interpolatingService.changeMyInter(askInterpolatingPublishParam, interId);
        if (interpolatingResult == InterpolatingResult.SUCCESS){
            return CommonResult.success(1,interpolatingResult.getMessage());
        }
        return CommonResult.failed(interpolatingResult.getMessage());
    }

    @ApiOperation("获取我的待确定的求内推列表")
    @GetMapping("/getMyToBeDetermedInterList")
    private CommonResult<CommonPage<MyInterpolatingListVo>> getMyToBeDeterminedInterList(@ApiParam("页码") @RequestParam(value = "pageNum",defaultValue = "1") Integer pageNum,
                                                                                     @ApiParam("每页信息条数") @RequestParam(value = "pageSize" ,defaultValue = "2") Integer pageSize){
        List<MyInterpolatingListVo> interpolatingListVos = interpolatingService.getMyToBeDeterminedInter(pageNum, pageSize);
        if (interpolatingListVos != null && interpolatingListVos.size() > 0){
            return CommonResult.success(CommonPage.restPage(interpolatingListVos),"获取成功");
        }
        return CommonResult.failed("未查询到相关信息");
    }

    @ApiOperation("获取个人发布的求内推详情（其中包括了可选内推人的信息）")
    @GetMapping("/choosePusher")
    private CommonResult<ChoosePusherVo> choosePusher(@ApiParam("求内推id号") @RequestParam("interId") Long interId){
        ChoosePusherVo choosePusherVo = interpolatingService.choosePusher(interId);
        if (choosePusherVo != null){
            return CommonResult.success(choosePusherVo,"获取成功");
        }
        return CommonResult.failed("未获取到相关信息");
    }
}
